#!/usr/bin/env bash

# Generate container tag names
# From https://github.com/weaveworks/scope/blob/master/tools/image-tag

set -o errexit
set -o pipefail

# If there is an explicit image tag set, just return it
if [ -n "$IMAGE_TAG" ]; then
  echo $IMAGE_TAG
  exit 0
fi

BRANCH_PREFIX=$(git rev-parse --abbrev-ref HEAD)
if [ "$1" = "branch" ] ; then
  echo "${BRANCH_PREFIX//\//-}"
else
  echo "${BRANCH_PREFIX//\//-}-$(git rev-parse --short HEAD)"
fi
